import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'
// 任务管理相关接口

/**
 * 任务分页查询
 * @param {object} data 参数  isTreat :1 待办，0 其他
 */
export function queryTaskPage({ status, reportMold, page, rows, pageFlag, searchWorld, isTreat = 0 }: any) {
  const params: any = {
    pageIndex: page,
    pageRows: rows,
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    isTreat
  }
  if (status) {
    params.status = status
  }
  if (reportMold) {
    params.reportMold = reportMold
  }
  if (searchWorld) {
    params.searchWorld = searchWorld
  }
  return request<IResponseData>({
    method: 'post',
    url: `/app/TaskManage/GetTaskList`,
    data: params
  })
}

/**
 * 任务详情
 * @param {string} caid 验收ID
 */
export function queryTaskDetail(caid: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/TaskManage/GetAcceptInfo?caid=${caid}`
  })
}

/**
 * 创建验收任务
 * @param {Object} data
 */
export function createSaveTask(data: any) {
  return request<IResponseData>({
    method: 'POST',
    url: `/app/TaskManage/SaveAccept`,
    data,
    headers: {
      repeatSubmit: false
    },
    loading: true,
    errorShow: true
  })
}

/**
 * 退回任务单(只退回app端提交的任务单)
 * @param {string} caid 验收ID
 */
export function returnTask(caid: string) {
  return request<IResponseData>({
    method: 'POST',
    url: `/app/TaskManage/AcceptBack?caid=${caid}`,
    headers: {
      repeatSubmit: false
    },
    errorShow: true
  })
}

/**
 * 提交验收信息-验证数据并修改状态为数据
 * @param {string} caid 验收ID
 */
export function commitAccet(caid: any) {
  return request<IResponseData>({
    method: 'POST',
    url: `/app/TaskManage/CommitAccrpt`,
    params: { caid },
    errorShow: true
  })
}

/**
 * 验收任务分配验收人员（选择验收人员）
 * @param {string} caid 验收ID
 * @param {Array} userList 验收人员 [{userID,userName},...]
 */
export function acceptAssignPerson(caid: string, userList: Array<any>) {
  return request<IResponseData>({
    method: 'POST',
    url: `/app/TaskManage/AcceptAssignPerson?caid=${caid}`,
    data: userList,
    headers: {
      repeatSubmit: false
    },
    errorShow: true
  })
}
/**
 * 验收任务复查（选择验收人员）
 * @param {string} caid 验收ID
 * @param {Array} userList 验收人员 [{userID,userName},...]
 */
export function acceptReview(caid: string, userList: Array<any>) {
  return request<IResponseData>({
    method: 'POST',
    url: `/app/TaskManage/AcceptReview?caid=${caid}`,
    data: userList,
    headers: {
      repeatSubmit: false
    },
    errorShow: true
  })
}
